using System;
using System.Globalization;

namespace PickGold.Charting.Design
{
	internal class LegendCollectionEditor : ChartCollectionEditor
	{
		public LegendCollectionEditor()
			: base(typeof(LegendCollection))
		{
		}

		protected override object CreateInstance(Type itemType)
		{
			if ((base.Context == null) || (base.Context.Instance == null))
			{
				return base.CreateInstance(itemType);
			}
			Chart instance = (Chart)base.Context.Instance;
			int num = instance.Legends.Count + 1;
			string name = "Legend" + num.ToString(CultureInfo.InvariantCulture);
			bool flag = true;
			while (flag)
			{
				flag = false;
				foreach (Legend legend in instance.Legends)
				{
					if (legend.Name == name)
					{
						flag = true;
					}
				}
				if (flag)
				{
					num++;
					name = "Legend" + num.ToString(CultureInfo.InvariantCulture);
				}
			}
			return new Legend(name);
		}
	}
}

